/**
 * 权限管理
 */
var PermissionUtil = {};
/**
 * 是否拥有权限
 * @param {{}} type
 * @return {Boolean}
 */
PermissionUtil.hasPermission = function (type) {
    if (window.inReview) {
        return true;
    }
    var permission = type[cc.sys.os];
    if (permission == undefined) {
        return false;
    } else if (permission == true) {
        return true;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        return jsb.reflection.callStaticMethod('PermissionUtil', 'hasPermission:', permission);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        return jsb.reflection.callStaticMethod(packageUri + '/utils/PermissionUtils', 'hasPermission', '(Ljava/lang/String;)Z', permission);
    }
    return true;
};
/**
 * 请求权限
 * @param {{}}type
 */
PermissionUtil.requestPermission = function (type) {
    if (window.inReview) {
        return;
    }
    var permission = type[cc.sys.os];
    if (!permission) {
        return false;
    } else if (permission == true) {
        return true;
    }
    if (cc.sys.os === cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod('PermissionUtil', 'requestPermission:', permission);
    } else if (cc.sys.os === cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + '/utils/PermissionUtils', 'requestPermission', '(Ljava/lang/String;)V', permission);
    }
};

/**
 * 权限定义
 * @type {{}}
 */
var PermissionType = {};
/**
 * 视频权限
 * @type {{}}
 */
PermissionType['Video'] = {};
PermissionType['Video'][cc.sys.OS_ANDROID] = 'android.permission.CAMERA';
PermissionType['Video'][cc.sys.OS_IOS] = 'video';
/**
 * 音频权限
 * @type {{}}
 */
PermissionType['Audio'] = {};
PermissionType['Audio'][cc.sys.OS_ANDROID] = 'android.permission.RECORD_AUDIO';
PermissionType['Audio'][cc.sys.OS_IOS] = 'audio';
/**
 * 定位权限
 * @type {{}}
 */
PermissionType['Location'] = {};
PermissionType['Location'][cc.sys.OS_ANDROID] = 'android.permission.ACCESS_FINE_LOCATION';
PermissionType['Location'][cc.sys.OS_IOS] = 'location';

/**
 * 定位权限
 * @type {{}}
 */
PermissionType['push'] = {};
PermissionType['push'][cc.sys.OS_ANDROID] = 'android.permission.ACCESS_NOTIFICATION_POLICY';
PermissionType['push'][cc.sys.OS_IOS] = 'push';

PermissionType['storage_write'] = {};
PermissionType['storage_write'][cc.sys.OS_ANDROID] = 'android.permission.WRITE_EXTERNAL_STORAGE';
PermissionType['storage_write'][cc.sys.OS_IOS] = true;

PermissionType['storage_read'] = {};
PermissionType['storage_read'][cc.sys.OS_ANDROID] = 'android.permission.READ_EXTERNAL_STORAGE';
PermissionType['storage_read'][cc.sys.OS_IOS] = true;